CLR ToolLib
Volume Number: 2
Issue Number: 6
Column Tag: Basic School
Add Three New Libraries to your CLR ToolLib
By Dave Kelly, Editorial Board
Hello!! This month MacTutor features three new MS BASIC libraries to add to
your CLR ToolLib collection. These routines were written by Clear Lake Research for
use on future versions of BASIC library disks. To make it easy to add them to your
ToolLib Libraries, we are providing a statement adder program to write the hex codes
directly to your disk. It will require that you already have CLR ToolLib in order to run
the Statement Adder program as the resource routines are used to save the new
libraries.
The new libraries are: RealFont, KbEquiv and setItemStyle. RealFont is a
Macintosh Font Manager function that returns TRUE if the font having the font number
fontNum is available in the given size in a resource file, or returns FALSE if the font
has to be scaled to that size. The syntax to call the CLR Realfont library is:
Realfont fontNum%,size%,boolean%
The following example shows the use of RealFont:
LIBRARY"NewLibraries
fontNum%=4 'Monaco font
size%=18
boolean%=0
RealFont fontNum%,size%,boolean%
PRINT boolean%
Each font type is represented by a different font number, in this case a four
represents the Monaco font. The size we are checking is 18. If size 18 exists in the
Monaco font the the variable boolean% returns a TRUE, otherwise if the font does not
exist in size 18 then a FALSE is returned. This routine is useful to create menus which
include the size of fonts to be used by your program. Some font numbers can be found
on page 290 of your MS BASIC manual.
KbEquiv may be used to add keyboard equivalents to your menus. MS BASIC
menus do no provide a way to add keyboard equivalents to your menus. An alternative is
to trap all keyboard input and branch to the appropriate subroutine, but that is would
require a separate routine which is not associated with the menu error trapping.
Usually, calls to the menu manager would indicate which keys are to be used as keyboard
equivalents to the menus. However, MS BASIC did not provide a way to use equivalent
keys. The syntax for the KbEquiv statement is:
KbEquiv Menunumber%,itemnumber%,key$
where Menunumber% is the menu and itemnumber% is the menu item where the
key will be added. The variable key$ is the one character key which will be used as the
equivalent key. The routine implementation is shown in the Menu Styles Demo later in
this article.
A warning: The KbEquiv routine does not yet check if the menu indicated actually
exists. Therefore be sure that you know your menu has already been created before
calling this routine. Unpredictable results will occur. The future released version of
this routine from CLR will check for the menu before setting up the keyboard
equivalent.
The third routine, setItemStyle, is also a member of the Menu Manager routines.
SetItemStyle changes the character style of the given menu item to the indicated
character style. The syntax is:
setItemStyle Menunumber%,itemnumber%,style%
where menunumber% is the number of the menu and itemnumber% is the number of
the item in that menu. Style% is an integer number representing the style of the menu
item. Style% is the same as the values used to represent the attributes of the
TEXTFACE statement. The bit for each attribute is listed on page 291 of your MS BASIC
manual. (Example: bold, shadow has a value of 17; Italic and underlined has a value of
12). The Menu Styles Demo demonstrates how to set up your own style menu.
To install your new libraries run the statement adder program listed below. The
KbEquiv, Real Font and setItemStyle routines will be added to a new file named
NewLibraries. This newly created file will be a CLR library file but without the LibInit
function; just the three new statements we've added this month. Next you will need to
run the Statement Mover program which is provided with the CLR Libraries disk.
Statement Mover is a handy BASIC program which will copy libraries from one file to
another. In fact, I recommend that you copy the libraries that you are using to your
BASIC program file (i. e. add the library resource to your BASIC program). The BASIC
program is stored in the data fork of the file, and the resource fork will then contain
the libraries used by the program. Use Satement Mover to copy the LibInit routine to
the NewLibraries file! LibInit is needed by BASIC to be sure that the Library file is a
MS BASIC Library. LibInit must be in the same file as each of the libraries that you use.
Of course if you choose to move the NewLibaries file into your already existing ToolLib
file, then you don't need the extra LibInit function. In fact, if you can spare the space,
you might want to merge all the library routines into a single ToolLib file using the
Statement Mover program. Here is a review list of everything CLR has published:
CLR LIBRARIES
ToolLib Original CLR ROM Interface
SpeechLib Speech stuff for MacinTalk
MathStatLib Math and Statistics routines
NewLibraries Output of this month's program
The ToolLib and MathStatLib are available on the CLR Utilities Disk from the
MacTutor Mail Order Store for $50. The SpeechLib is available seperately on the CLR
Speech disk for $20. We tried to encourage CLR to combine the two products to avoid
customer confusion, but they were unable to do so.
The Menu Styles Demo will try to open the NewLibraries file, so you should be
sure that LibInit is moved to the New Libraries file or that the program calls the name
of the Library containing the setItemStyle and KbEquiv routines (RealFont is not used
in the demo).
'Statement Adder
' for RealFont, KbEquiv, and setItemStyle libraries
'By Clear Lake Research and David Kelly
'© Clear Lake Re search, Inc.
'used with permission
'NOTE: The hex codes for RealFont, KbEquiv, setItemStyle
'are copyrighted by Clear Lake Re search.